package com.hcy.controller.manager;

import com.hcy.manager.DriverInfoBz;
import com.hcy.manager.dto.request.DriverInfoAddRequestDTO;
import com.hcy.manager.dto.request.DriverInfoRequestDTO;
import com.hcy.manager.dto.response.DriverInfoDetailsResponseDTO;
import com.hcy.manager.dto.response.DriverInfoResponseDTO;
import com.hcy.rabbitbasicmodel.dto.MyPage;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.rabbitbasicmodel.signl.Delete;
import com.hcy.rabbitbasicmodel.signl.Query;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/4/26
 **/
@RestController
@Slf4j
@RequestMapping("/managerDriver")
public class DriverManagerController {

    @Autowired
    private DriverInfoBz driverInfoBz;

    /**
     * @Author huchenying
     * @Description 获取司机列表
     * @Date 2022/4/26 22:21
     **/
    @PostMapping("/getDriverList")
    public ResponseData<MyPage<DriverInfoResponseDTO>> getDriverList(@Validated(Query.class) @RequestBody DriverInfoRequestDTO requestDTO){
        log.info("getDriverList start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<MyPage<DriverInfoResponseDTO>> responseData = new ResponseData<>();
        try {
            MyPage<DriverInfoResponseDTO> responseDTOMyPage = driverInfoBz.getDriverList(requestDTO);
            return responseData.success(responseDTOMyPage);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("获取列表信息失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  取消签约
     * @Date 2022/4/26 23:13
     **/
    @PostMapping("/cancelSig")
    public ResponseData<Object> cancelSig(@Validated(Delete.class) @RequestBody DriverInfoRequestDTO requestDTO){
        log.info("cancelSig start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        try {
            driverInfoBz.cancelSig(requestDTO);
            return ResponseData.success();
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return ResponseData.fail0("取消失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  添加或更新 driverInfo
     * @Date 2022/4/27 0:02
     **/
    @PostMapping("/addOrUpdateDriverInfo")
    public ResponseData<DriverInfoDetailsResponseDTO> addOrUpdateDriverInfo(@Validated @RequestBody DriverInfoAddRequestDTO requestDTO){
        log.info("addOrUpdateDriverInfo start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<DriverInfoDetailsResponseDTO> responseData = new ResponseData<>();
        try {
            DriverInfoDetailsResponseDTO responseDTO = driverInfoBz.addOrUpdateDriverInfo(requestDTO);
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("添加失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  获取详情
     * @Date 2022/4/27 1:42
     **/
    @PostMapping("/getDriverDetails")
    public ResponseData<DriverInfoDetailsResponseDTO> getDriverDetails(@Validated(Delete.class)@RequestBody DriverInfoRequestDTO requestDTO){
        log.info("getDriverDetails start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<DriverInfoDetailsResponseDTO> responseData = new ResponseData<>();
        try {
            DriverInfoDetailsResponseDTO responseDTO = driverInfoBz.getDriverDetails(requestDTO);
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("获取详情失败");
        }
    }
}
